package org.example.com.kotlinlab.delegate.property_delegate.observable_delegate.demo02

import kotlin.properties.Delegates

/**
 * Delegates.vetoable()
 * 每次赋值都会调用其onChange()函数，只有onChange()返回true时才会赋值成功。
 */
class User{
    var name:Int by Delegates.vetoable(1){ _, _, newValue ->
        newValue > 3
    }
}

fun main() {
    val user = User()
    println(user.name)
    user.name = 2
    println(user.name)
    user.name = 3
    println(user.name)
    user.name = 4
    println(user.name)
}